import wx


class Myframe(wx.Frame):
    def __init__(self, parent, title):
        super(Myframe, self).__init__(parent, title=title,
                                      size=(600, 400))
        self.panel = wx.Panel(self)

        vbox = wx.BoxSizer(wx.VERTICAL)

        # 创建ScrolledW�ScrolledWindow，并设置其大小和滚动条
        scrolled = wx.ScrolledWindow(self.panel, -1,
                                     style=wx.VSCROLL)

        scrolled.SetScrollRate(0, 10)  # 设置滚动速度

        sizer = wx.BoxSizer(wx.VERTICAL)
        for i in range(30):
            label = "Line {}".format(i + 1)
            statistics = wx.StaticText(scrolled, label=label)
            sizer.Add(statistics, 0, wx.EXPAND | wx.ALL, 5)

        scrolled.SetSizer(sizer)  # 将sizer设置为ScrolledWindow的布局管理器
        scrolled.FitInside()  # 调整Scrolledwindow的大小以适应其内容

        # 将ScrolledWindow添加到vbox，vbox是panel的布局管理器
        vbox.Add(scrolled, 1, wx.EXPAND | wx.ALL, 5)
        self.panel.SetSizer(vbox)  # 将vbox设置为panel的布局管理器
        self.panel.Layout()  # 更新panel的布局


app = wx.App(False)
frame = Myframe(None, 'ScrolledWindow')
frame.Show(True)
app.MainLoop()
